<?php
/**
 *（Logic）
 */
namespace App\Logic\Amazon\Api;

class OrderWork
{
    /**
     * 用命令通过订单号补订单
     * @param $accounts
     * @param $orderIDs
     * @return void
     * @throws \Exception
     */
    public static function getOrdersViaOrderIDs($accounts,$orderIDs)
    {
        $requiredConfig = RequiredConfig::getInit();
        foreach ($accounts as $account){
            $config = $requiredConfig->configuration($account->refresh_token,$account->aws_region);
            $flag = Orders::apiGetOrdersViaOrderIDs($config,$account,$orderIDs);
            if($flag)break;
            sleep(1);
        }
    }

    /**
     * 用命令批量补订单
     * @param $accounts
     * @return void
     * @throws \Exception
     */
    public static function getOrders($accounts)
    {
        $requiredConfig = RequiredConfig::getInit();
        $re = [];
        foreach ($accounts as $account){
            $config = $requiredConfig->configuration($account->refresh_token,$account->aws_region);
            $last_updated_after = null;
            $last_updated_before = null;
            $times = 144 * 1 * 0.5 * 0.5;
            $re[$account->id] = Orders::apiGetOrders($config,$account,$last_updated_after,$last_updated_before,$times);
            sleep(1);
        }
        dump($re);
    }

    /**
     * 用命令测试API
     * @param $account
     * @param $orderID
     * @return void
     * @throws \Exception
     */
    public static function testAPIViaOrderID($account,$orderID): void
    {
        $requiredConfig = RequiredConfig::getInit();
        $config = $requiredConfig->configuration($account->refresh_token,$account->aws_region);
        $flag = Orders::testAPIViaOrderID($config, $account, $orderID);
        dump($flag);
    }
}
